/****************************************************************************
*
* Header Files
*
****************************************************************************/
#include "ctc_const.h"
#include "ctc_error.h"

#include "sys_usw_common.h"
#include "sys_usw_xdata_api.h"
#include "ctc_at_xdata.h"

int32
ctc_at_xdata_init(uint8 lchip, void* xdata_global_cfg)
{
    uint8 lchip_start               = 0;
    uint8 lchip_end                 = 0;

    LCHIP_CHECK(lchip);

    CTC_AT_FOREACH_LCHIP(lchip_start, lchip_end, 1)
    {
        if (MCHIP_XDATA(lchip)->xdata_init)
        {
            CTC_ERROR_RETURN(MCHIP_XDATA(lchip)->xdata_init(lchip));
        }
    }

    return CTC_E_NONE;
}

int32
ctc_at_xdata_deinit(uint8 lchip)
{
    uint8 lchip_start               = 0;
    uint8 lchip_end                 = 0;

    LCHIP_CHECK(lchip);
    CTC_AT_FOREACH_LCHIP(lchip_start, lchip_end, 1)
    {
        if (MCHIP_XDATA(lchip)->xdata_deinit)
        {
            CTC_ERROR_RETURN(MCHIP_XDATA(lchip)->xdata_deinit(lchip));
        }
    }

    return CTC_E_NONE;
}

int32
ctc_at_xdata_set_profile(uint8 lchip, ctc_xdata_prof_t *p_prof)
{
    uint8 lchip_start = 0;
    uint8 lchip_end = 0;
    int32 ret = CTC_E_NONE;

    FEATURE_SUPPORT_CHECK(CTC_FEATURE_XDATA);
    LCHIP_CHECK(lchip);

    CTC_FOREACH_LCHIP(lchip_start, lchip_end, 1)
    {
        if (MCHIP_XDATA(lchip)->set_profile)
        {
            CTC_FOREACH_ERROR_RETURN(CTC_E_NONE,
                                     ret,
                                     MCHIP_XDATA(lchip)->set_profile(lchip, p_prof));
        }
    }

    return ret;
}

int32
ctc_at_xdata_get_profile(uint8 lchip, ctc_xdata_prof_t* p_prof)
{
    int32 ret = CTC_E_NONE;

    FEATURE_SUPPORT_CHECK(CTC_FEATURE_XDATA);
    LCHIP_CHECK(lchip);

    if (MCHIP_XDATA(lchip)->get_profile)
    {
        CTC_ERROR_RETURN(MCHIP_XDATA(lchip)->get_profile(lchip, p_prof));
    }

    return ret;
}

int32
ctc_at_xdata_set_local(uint8 lchip, ctc_xdata_local_t* p_local)
{
    uint8 lchip_start = 0;
    uint8 lchip_end = 0;
    int32 ret = CTC_E_NONE;

    FEATURE_SUPPORT_CHECK(CTC_FEATURE_XDATA);
    LCHIP_CHECK(lchip);

    CTC_FOREACH_LCHIP(lchip_start, lchip_end, 1)
    {
        if (MCHIP_XDATA(lchip)->set_local)
        {
            CTC_FOREACH_ERROR_RETURN(CTC_E_NONE,
                                     ret,
                                     MCHIP_XDATA(lchip)->set_local(lchip, p_local));
        }
    }

    return ret;
}

int32
ctc_at_xdata_get_local(uint8 lchip, ctc_xdata_local_t* p_local)
{
    int32 ret = CTC_E_NONE;

    FEATURE_SUPPORT_CHECK(CTC_FEATURE_XDATA);
    LCHIP_CHECK(lchip);

    if (MCHIP_XDATA(lchip)->get_local)
    {
        CTC_ERROR_RETURN(MCHIP_XDATA(lchip)->get_local(lchip, p_local));
    }

    return ret;
}


int32
ctc_at_xdata_set_path(uint8 lchip, ctc_xdata_path_t* p_path)
{
    uint8 lchip_start = 0;
    uint8 lchip_end = 0;
    int32 ret = CTC_E_NONE;

    FEATURE_SUPPORT_CHECK(CTC_FEATURE_XDATA);
    LCHIP_CHECK(lchip);

    CTC_FOREACH_LCHIP(lchip_start, lchip_end, 1)
    {
        if (MCHIP_XDATA(lchip)->set_path)
        {
            CTC_FOREACH_ERROR_RETURN(CTC_E_NONE,
                                     ret,
                                     MCHIP_XDATA(lchip)->set_path(lchip, p_path));
        }
    }

    return ret;
}

int32
ctc_at_xdata_get_path(uint8 lchip, ctc_xdata_path_t* p_path)
{
    int32 ret = CTC_E_NONE;

    FEATURE_SUPPORT_CHECK(CTC_FEATURE_XDATA);
    LCHIP_CHECK(lchip);

    if (MCHIP_XDATA(lchip)->get_path)
    {
        CTC_ERROR_RETURN(MCHIP_XDATA(lchip)->get_path(lchip, p_path));
    }

    return ret;
}



